package com.showde.shoppingmall.utils;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.showde.shoppingmall.R;

public class ToastUtils {

	private static final int viewLayoutId = R.layout.view_customer_toast;

	private static final int NO_MSGID = 0x10001;

	public static void showToast(Context context, String msg) {
		show(context, NO_MSGID, msg);
	}

	public static void showToast(Context context, int msgId) {
		show(context, msgId, null);
	}

	public static void show(Context context, int msgId, String msg) {
		View toastRoot = LayoutInflater.from(context).inflate(viewLayoutId,
				null);
		TextView toast_tv = (TextView) toastRoot.findViewById(R.id.toast_tv);

		String msgStr = null;
		if (NO_MSGID == msgId) {
			msgStr = msg;
		} else {
			msgStr = context.getString(msgId);
		}

		toast_tv.setText(msgStr);
		Toast toast = new Toast(context);
		// 设置Toast的位置
		toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
		toast.setDuration(Toast.LENGTH_SHORT);
		// 让Toast显示为我们自定义的样子
		toast.setView(toastRoot);
		toast.show();
	}
}
